package com.example.java1query.infrastructure;

import com.example.java1query.domain.Community;
import com.example.java1query.domain.Hero;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface JpaCommunity extends JpaRepository<Community ,Long> {

    Community findByCommunityCode(String code);
    @Query(value = "select distinct * from hero" +
            " left join community c2 on hero.community_code = c2.community_code" +
            " where hero.profession like ?1%" ,nativeQuery = true)
    List<Community> find(String profession);
    @Query(value = "select distinct c from Hero h" +
            " left join h.community c" +
            " where h.profession = ?1")
    List<Community> findJpql(Hero.Profession profession);
    @Query("select distinct c from Community c" +
            " left join fetch c.heroes h" +
            " where h.profession = ?1")
    List<Community> findJpql1(Hero.Profession profession);






}
